<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>忧郁小王子-修改用户</title>
  <link rel="stylesheet" href="/admin/assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="/admin/assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href="/admin/assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href="/admin/assets/css/admin.css">
  <script src="/admin/assets/vendors/nprogress/nprogress.js"></script>
</head>
<body>
  <script>NProgress.start()</script>

  <div class="main">
   {{include '../common/header.html'}}
    <div class="container-fluid"  style="margin-left: 30%">
      <div class="page-title">
        <h1>修改用户</h1>
      </div>
      <!-- 有错误信息时展示 -->
      <!-- <div class="alert alert-danger">
        <strong>错误！</strong>发生XXX错误
      </div> -->
      <div class="row">
        <div class="col-md-6">
          <form method="post" enctype="multipart/form-data" action="/admin/modifyUser">
            <div class="form-group">
              <label>头像</label>
              <div class="form-group">
                <label class="form-image">
                <!--  <input id="avatar" type="file">
                  <img src="/admin/assets/img/default.png">-->
                  <input id="feature" type="file" class="form-control" name="profilePhoto" onchange="previewFile()">
                  <img src="/admin/assets/img/default.png" height="150" width="300" alt="请上传图片..."/>
                  <i class="mask fa fa-upload"></i>
                </label>
              </div>
            </div>
            <div class="form-group">
              <label>ID</label>
              <input value="{{@user._id}}" name="_id" class="form-control" type="text" readonly>
            </div>
            <div class="form-group">
              <label>用户名</label>
              <input value="{{user.username}}" name="username" class="form-control" type="text" placeholder="请输入用户名">
            </div>
            <div class="form-group">
              <label>邮箱</label>
              <input value="{{user.email}}" name="email" class="form-control" type="email" placeholder="请输入邮箱">
            </div>
            <div class="form-group">
              <label>密码</label>
              <input value="{{user.password}}" name="password" class="form-control" type="text" placeholder="请输入密码">
            </div>
            <div class="form-group">
              <label>角色</label>
                <select class="form-control m-b" name="role">
                  {{if user.role == '管理员'}}
                  <option value="管理员" selected>管理员</option>
                  <option value="用户">用户</option>
                  {{else}}
                  <option value="管理员">管理员</option>
                  <option value="用户" selected>用户</option>
                  {{/if}}
                </select>
            </div>
            <div class="form-group">
              <label>状态</label>
              <select class="form-control m-b" name="state">
                {{if user.state == 1 }}
                <option value="0">禁用</option>
                <option value="1" selected>启用</option>
                {{else}}
                <option value="0" selected>禁用</option>
                <option value="1">启用</option>
                {{/if}}
              </select>
            </div>
            <div class="form-group">
              <button class="btn btn-primary" type="submit">提交修改</button>
            </div>
          </form>
        </div>
    </div>
  </div>
  </div>
  {{include '../common/leftMenu.html'}}
  <script src="/admin/assets/vendors/jquery/jquery.js"></script>
  <script src="/admin/assets/vendors/bootstrap/js/bootstrap.js"></script>
  <script>NProgress.done()</script>
    <script>
      function previewFile() {
        let preview = document.querySelector('img');
        let file  = document.querySelector('input[type=file]').files[0];
        let reader = new FileReader();
        reader.onloadend = function () {
          preview.src = reader.result;
        }
        if (file) {
          reader.readAsDataURL(file);
        } else {
          preview.src = "";
        }
      }
    </script>
</body>
</html>
